<?php
class Block_Core_Grid_Abstract
    extends Block_Core_Main_Content
{
    protected $_columns = array();
 
    protected $_masaction = null;

    protected $_collection = null;

    protected $_action = null;

    public function __construct()
    {
        parent::__construct();
        $this->setTemplate('grid/template.phtml');
        $this->initGrid();
    }

    public function initGrid()
    {
        $this->prepareCollection();
        $this->prepareColumns();
        $this->prepareMasaction();
        return $this;
    }

    public function prepareCollection()
    {
        return $this;
    }

    public function prepareMasaction()
    {
        return $this;
    }

    public function prepareColumns()
    {
        return $this;
    }

    protected function _addColumn($params = array())
    {
        $data = new Object();
        $data->setData($params);

        $this->_columns[] = $data;
        return $this;
    }

    public function getColumns()
    {
        return $this->_columns;
    }

    protected function _addMasaction($params = array())
    {
        $data = new Object();
        $data->setData($params);

        $this->_masaction = $data;
        return $this;
    }

    public function getMasaction()
    {
        return $this->_masaction;
    }

    public function isMasaction()
    {
        return isset($this->_masaction)?1:0;
    }

    public function setCollection($collection)
    {
        $this->_collection = $collection;
        return $this;
    }

    protected function _addAction($params = array())
    {
        $data = new Object();
        $data->setData($params);
        $this->_action = $data;

        return $this;
    }

    public function getCollection()
    {
        return $this->_collection;
    }

    public function isAction()
    {
        return isset($this->_action)?true:false;
    }

    public function getAction()
    {
        return $this->_action;
    }

    /**
     * TODO: поправити!!!!!
     * Get action url in grid
     * @param array $action
     * @param model $row
     */
    public function getActionUrl($action, $row)
    {
        $url = Bootstrap::getUrl($action['url']);
        $url .= $action['value'].'/'.$row->getData($action['index']);
        return $url;
    }
}